package com.jiang.daily.Q3066;

import java.util.PriorityQueue;

/**
 * @author Jiang
 * @version 1.0
 * @date 2025/01/15 0:19
 */
class Solution {
    public int minOperations(int[] nums, int k) {
        int len = nums.length;
        PriorityQueue<Long> q = new PriorityQueue<>();
        for (int i = 0; i < len; i++) {
            q.offer((long) nums[i]);
        }
        int cnt = 0;
        while (len >= 2) {
            long num1 = q.poll();
            long num2 = q.poll();

            if (num1 >= k)
                return cnt;
            q.offer(2 * Math.min(num1, num2) + Math.max(num1, num2));

            len--;
            cnt++;
        }
        return cnt;
    }
}